/***************************************************************************
 *   Copyright (C) 2008 by Eduardo Gurgel Pinho                            *
 *   edgurgel@gmail.com                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#ifndef __COLOR_H__
#define __COLOR_H__

#include <boost/serialization/nvp.hpp>
#include <boost/serialization/version.hpp>

namespace Sirat {

namespace Common {
	
/**
 * RGB Color class.
 * The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors.
 */
		
struct Color {
	/**
	 * Simple constructor.
	 * @param _red X value
	 * @param _green Y value
	 * @param _blue Blue value
	 * @see Color(void)
	 */
	Color(const double _red,const double _green,const double _blue);
	
	/**
	* Default constructor.
	* Boost Serialization needs a default constructor
	* @see Color(const Color&)
	*/
	Color();
	
	/**
	 * Copy constructor.
	 */
	Color(const Color&);
	
	/**
	 * Destructor
	 */
	~Color();

	void show() const;
	
	/**
	 * Copy assignment operator.
	 */
	Color& operator=(const Color&);
	
	/**
	 * Array subscripting.
	 */
	double operator[](const int&) const;
	
	/**
	 * Plus operation
	 */
	Color operator+(const Color&) const;
	Color operator-(const Color&) const;
	Color operator*(const Color&) const;
	friend Color operator*(const Color&,const double);
	friend Color operator*(const double,const Color&);
        
	double red,green,blue;
	
private:
	friend class boost::serialization::access;
	template<class Archive> void serialize(Archive&, const unsigned int);
};

template<class Archive> void Color::serialize(Archive& ar, const unsigned int /* file_version */){
	ar & BOOST_SERIALIZATION_NVP(red)
		& BOOST_SERIALIZATION_NVP(green)
		& BOOST_SERIALIZATION_NVP(blue);
}

inline
double Color::operator[](const int& _index) const {
	switch(_index) {
		case 1: return red;
		case 2: return green;
		case 3: return blue;
		default: exit(1);
	}
}

inline
Color Color::operator+(const Color& _color) const {
	return Color(red + _color.red,green + _color.green,blue + _color.blue);
}

inline
Color Color::operator-(const Color& _color) const {
	return Color(red - _color.red,green - _color.green,blue - _color.blue);
}

inline
Color Color::operator*(const Color& _color) const {
	return Color(red * _color.red,green * _color.green,blue * _color.blue);
}
 
inline
Color operator*(const Color& _color,const double _value) {
	return Color(_color.red* _value,_color.green * _value,_color.blue * _value);
}

inline
Color operator*(const double _value,const Color& _color) {
	return _color*_value;
}

}

}
#endif
